package com.lzh.crm.controller;

import com.lzh.crm.pojo.Result;
import com.lzh.crm.pojo.Employee;
import com.lzh.crm.service.EmployeeService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeService emService;

    //增加员工信息
    @PostMapping("/insert")
    public Result insert(@RequestBody @Valid Employee em){
        emService.insert(em);
        return Result.success();
    }

    //删除员工信息
    @DeleteMapping("/delete")
    public Result delete(Integer emId){
        emService.delete(emId);
        return Result.success("删除成功");
    }

    //修改员工信息
    @PutMapping("/update")
    public Result update(@RequestBody Employee em){
        emService.update(em);
        return Result.success("修改成功");
    }

    //查询员工信息
    @GetMapping("/selectAll")
    public Result<List<Employee>> selectAll(){
        List<Employee> e = emService.selectAll();
        return Result.success(e);
    }

    //条件查询员工信息
    @GetMapping("/selectNeed")
    public Result<List<Employee>> selectNeed(Employee em){
        List<Employee> e = emService.selectNeed(em);
        return Result.success(e);
    }
}
